﻿using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace Nirvana
{
    [CustomEditor(typeof(ParticleSystemImportRule), true)]
    public class ParticleSystemImportRuleEditor : Editor
    {
        private SerializedProperty includeRegexs;
        private SerializedProperty excludeRegexs;

        private int startindex = -1;
        private Vector2 pos;

        private SerializedProperty checkPrvWarm, maxPrvwarmTime, maxParticleCount;

        private void OnEnable()
        {
            if (this.target == null)
            {
                return;
            }
            SerializedObject serializedObject = base.serializedObject;
            this.includeRegexs = serializedObject.FindProperty("includeRegexs");
            this.excludeRegexs = serializedObject.FindProperty("excludeRegexs");

            this.checkPrvWarm = serializedObject.FindProperty("checkPrvWarm");
            this.maxPrvwarmTime = serializedObject.FindProperty("maxPrvwarmTime");
            maxParticleCount = serializedObject.FindProperty("maxParticleCount");
        }


        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            EditorGUILayout.HelpBox("\n此规则文件用于检测粒子的预热开启状态和粒子最大数量。\n", MessageType.Info);
            EditorGUILayout.Space();

            GUILayout.Label("匹配规则", GUITheme.LabelTitleStyle);
            GUILayoutEx.BeginContents();
            GUI.color = Color.yellow;
            EditorGUILayout.HelpBox("注意：规则文件只会检测同一父目录或同一级目录下的资源。\n", MessageType.None);
            GUI.color = Color.white;
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(this.includeRegexs);
            EditorGUILayout.PropertyField(this.excludeRegexs);

            GUILayoutEx.EndContents();
            EditorGUILayout.Space();


            EditorGUILayout.PropertyField(this.checkPrvWarm);
            EditorGUILayout.PropertyField(this.maxPrvwarmTime);
            EditorGUILayout.PropertyField(this.maxParticleCount);

            EditorGUILayout.Space();

            ParticleSystemImportRule rule = this.target as ParticleSystemImportRule;
            //EditorGUILayout.BeginHorizontal(GUITheme.ListItemHeaderStyle);
            if (GUILayoutEx.ActionButton("检测粒子"))
            {
                rule.CheckParticleSystemRule();
            }
            if (GUILayoutEx.ActionButton("关闭预热"))
            {

                rule.CloseParticleSystemPrvwarm();
            }
            if (GUILayoutEx.ActionButton("设置最大粒子数"))
            {
                rule.SetParticleSystemMaxCount();
            }
            //EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();


            var list = rule.Report.Reports;
            if (list.Count > 0)
            {
                EditorGUILayout.PrefixLabel(string.Format("Report({0}):  (鼠标滚轮滑动)", list.Count));
                AssetCheckReportItem.Show(list, ref this.pos, ref this.startindex);
            }

            serializedObject.ApplyModifiedProperties();
        }
    }
}

